package com.example.shop_2212.adapter

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.CategoryEntity
import com.example.base.entity.Child
import com.example.shop_2212.R
import com.example.shop_2212.utils.GlideUtils
//二级分类的适配器
class TwoAdapter:BaseQuickAdapter<CategoryEntity,BaseViewHolder>(R.layout.item_two) {
    override fun convert(holder: BaseViewHolder, item: CategoryEntity) {
        holder.setText(R.id.two_tv,"----${item.name}----")
        val rvTwo = holder.getView<RecyclerView>(R.id.two_rv)
        //定义适配器，绑定适配器，加载数据
        val childAdapter = ChildAdapter()
        childAdapter.data.clear()
        childAdapter.data.addAll(item.child)
        rvTwo.adapter = childAdapter
        rvTwo.layoutManager = GridLayoutManager(context,3)
    }
}
//二级分类中rv的适配器
class ChildAdapter:BaseQuickAdapter<Child,BaseViewHolder>(R.layout.item_two_child){
    override fun convert(holder: BaseViewHolder, item: Child) {
        GlideUtils.loadCircleImage(context,item.extra,holder.getView(R.id.child_iv))
        holder.setText(R.id.child_tv,item.name)
       /* holder.itemView.setOnClickListener {
            ARouter.getInstance().build("/app/CateDetailActivity").withInt("cid",item.id).withString("cname",item.name).navigation()
            //ToastUtils.showLong(item.name)
        }*/
    }

}